package br.com.musclebook.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "USER_EXERCISE")
@NamedQueries({
    @NamedQuery(name = "UserExercise.listByCategory", query = "select userExerc from UserExercise userExerc where userExerc.primaryCategory = :category and userExerc.user.id = :userId order by upper(userExerc.name)"),
    @NamedQuery(name = "UserExercise.listNames", query = "select userExerc.name from UserExercise userExerc where upper(userExerc.name) like :name and userExerc.user.id = :userId order by upper(userExerc.name)"),
    @NamedQuery(name = "UserExercise.listByName", query = "select userExerc from UserExercise userExerc where upper(userExerc.name) like :name and userExerc.user.id = :userId order by upper(userExerc.name)")
    })
@PrimaryKeyJoinColumn(name = "EXERCISE_ID")
public class UserExercise extends Exercise implements Serializable {

    private static final long serialVersionUID = 1L;

    @ManyToOne
    @JoinColumn(name="USER_ID")
    private User user;
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "CREATION")
    private Date creation;
    
    public UserExercise() {
	this.creation = new Date();
    }
    
    public UserExercise(User user) {
	this();
	this.user = user;
    }

    public User getUser() {
	return user;
    }

    public void setUser(User user) {
	this.user = user;
    }
    
    public Date getCreation() {
	return creation;
    }

    public void setCreation(Date creation) {
	this.creation = creation;
    }

}
